﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RemoteAccessScanner;
using System.Collections.ObjectModel;

namespace RemoteAccessMonitorTests
{

    [TestClass]
    public class RemoteAccessMonitorTests
    {

        [TestMethod]
        public void CheckingProcess_Construct_NotNull()
        {
            ISystemProcessProvider supplier = new MockGoodSystemProcessSupplier();
            ICheckingProcess checker = new CheckingProcess(supplier);
            Assert.IsNotNull(checker);
        }

        [TestMethod]
        public void CheckRemoteAcess_NoConnectOrDisconnect()
        {
            ISystemProcessProvider supplier = new MockGoodSystemProcessSupplier();
            ICheckingProcess checker = new CheckingProcess(supplier);
            ObservableCollection<ConnectedUser> connectedUsers = new ObservableCollection<ConnectedUser>();
            CheckRemoteAccessResponse response = checker.CheckRemoteAccess(connectedUsers);

            Assert.AreEqual(0, response.ConnectedUsers.Count);
            Assert.AreEqual(0, response.RemoteAccessEvents.Count);
        }

        [TestMethod]
        public void CheckRemoteAcess_UserAddedOnConnect()
        {
            ISystemProcessProvider supplier = new MockBadSystemProcessSupplier();
            ICheckingProcess checker = new CheckingProcess(supplier);
            ObservableCollection<ConnectedUser> connectedUsers = new ObservableCollection<ConnectedUser>();

            CheckRemoteAccessResponse response = checker.CheckRemoteAccess(connectedUsers);

            Assert.AreEqual(1, response.ConnectedUsers.Count);
            Assert.AreEqual(1, response.RemoteAccessEvents.Count);
        }

        [TestMethod]
        public void CheckRemoteAcess_UserRemovedOnDisconnect()
        {
            ISystemProcessProvider supplier = new MockGoodSystemProcessSupplier();
            ICheckingProcess checker = new CheckingProcess(supplier);
            ObservableCollection<ConnectedUser> connectedUsers = new ObservableCollection<ConnectedUser>();
            connectedUsers.Add(new ConnectedUser() { UserName = "TEST\\UserName" });

            CheckRemoteAccessResponse response = checker.CheckRemoteAccess(connectedUsers);

            Assert.AreEqual(0, response.ConnectedUsers.Count);
            Assert.AreEqual(1, response.RemoteAccessEvents.Count);
        }

        [TestMethod]
        public void CheckRemoteAcess_UserIgnoredDuringSession()
        {
            ISystemProcessProvider supplier = new MockBadSystemProcessSupplier();
            ICheckingProcess checker = new CheckingProcess(supplier);
            ObservableCollection<ConnectedUser> connectedUsers = new ObservableCollection<ConnectedUser>();
            connectedUsers.Add(new ConnectedUser() { UserName = "TEST\\UserName" });

            CheckRemoteAccessResponse response = checker.CheckRemoteAccess(connectedUsers);

            Assert.AreEqual(connectedUsers[0].UserName, response.ConnectedUsers[0].UserName);
            Assert.AreEqual(0, response.RemoteAccessEvents.Count);
        }
    }
}
